﻿using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Should.Fluent;

namespace Is.Test
{
    [TestClass]
    public class ContainsCollectionExtensionsTest
    {
        [TestMethod]
        public void Test_IsNull()
        {
            ICollection<string> strings = null;
            strings.Is().Null().Should().Be.True();
            strings.Is().Not.Null().Should().Be.False();
            strings = new List<string>();
            strings.Is().Null().Should().Be.False();
            strings.Is().Not.Null().Should().Be.True();
        }

        [TestMethod]
        public void Test_IsEmpty()
        {
            ICollection strings = new List<string>();
            strings.Is().Empty().Should().Be.True();
            strings.Is().Not.Empty().Should().Be.False();
            strings = new List<string>() { "alma" };
            strings.Is().Empty().Should().Be.False();
            strings.Is().Not.Empty().Should().Be.True();

            ICollection nullstrings = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => nullstrings.Is().Empty());
        }

        [TestMethod]
        public void Test_IsNullOrEmpty()
        {
            ICollection strings = new List<string>();
            strings.Is().NullOrEmpty().Should().Be.True();
            strings.Is().Not.NullOrEmpty().Should().Be.False();
            strings = new List<string>();
            strings.Is().NullOrEmpty().Should().Be.True();
            strings.Is().Not.NullOrEmpty().Should().Be.False();
            strings = new List<string>() { "alma" };
            strings.Is().NullOrEmpty().Should().Be.False();
            strings.Is().Not.NullOrEmpty().Should().Be.True();
        }

        [TestMethod]
        public void Test_Is_Contains()
        {
            ICollection strings = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Contains().Zero());
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Contains().One());
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Contains().Exactly(0));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Contains().Exactly(1));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Contains().AtLeast(1));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Contains().AtLeast(0));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Contains().AtLeast(2));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Contains().NoMoreThan(1));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Contains().NoMoreThan(0));

            strings = new List<string>();
            strings.Is().Contains().Zero().Should().Be.True();
            strings.Is().Contains().One().Should().Be.False();
            strings.Is().Contains().Exactly(0).Should().Be.True();
            strings.Is().Contains().Exactly(1).Should().Be.False();
            strings.Is().Contains().AtLeast(1).Should().Be.False();
            strings.Is().Contains().AtLeast(0).Should().Be.True();
            strings.Is().Contains().AtLeast(2).Should().Be.False();
            strings.Is().Contains().NoMoreThan(1).Should().Be.True();
            strings.Is().Contains().NoMoreThan(2).Should().Be.True();
            strings.Is().Contains().NoMoreThan(0).Should().Be.True();

            strings = new List<string>() { "alma" };
            strings.Is().Contains().Zero().Should().Be.False();
            strings.Is().Contains().One().Should().Be.True();
            strings.Is().Contains().Exactly(1).Should().Be.True();
            strings.Is().Contains().Exactly(2).Should().Be.False();
            strings.Is().Contains().AtLeast(1).Should().Be.True();
            strings.Is().Contains().AtLeast(0).Should().Be.True();
            strings.Is().Contains().AtLeast(2).Should().Be.False();
            strings.Is().Contains().NoMoreThan(1).Should().Be.True();
            strings.Is().Contains().NoMoreThan(2).Should().Be.True();
            strings.Is().Contains().NoMoreThan(0).Should().Be.False();
        }

        [TestMethod]
        public void Test_Is_Not_Contains()
        {
            ICollection strings = null;
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Not.Contains().Zero());
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Not.Contains().One());
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Not.Contains().Exactly(0));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Not.Contains().Exactly(1));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Not.Contains().AtLeast(1));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Not.Contains().AtLeast(0));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Not.Contains().AtLeast(2));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Not.Contains().NoMoreThan(1));
            Should.Core.Assertions.Assert.Throws<ArgumentNullException>(() => strings.Is().Not.Contains().NoMoreThan(0));

            strings = new List<string>();
            strings.Is().Not.Contains().Zero().Should().Be.False();
            strings.Is().Not.Contains().One().Should().Be.True();
            strings.Is().Not.Contains().Exactly(0).Should().Be.False();
            strings.Is().Not.Contains().Exactly(1).Should().Be.True();
            strings.Is().Not.Contains().AtLeast(1).Should().Be.True();
            strings.Is().Not.Contains().AtLeast(0).Should().Be.False();
            strings.Is().Not.Contains().AtLeast(2).Should().Be.True();
            strings.Is().Not.Contains().NoMoreThan(1).Should().Be.False();
            strings.Is().Not.Contains().NoMoreThan(2).Should().Be.False();
            strings.Is().Not.Contains().NoMoreThan(0).Should().Be.False();

            strings = new List<string>() { "alma" };
            strings.Is().Not.Contains().Zero().Should().Be.True();
            strings.Is().Not.Contains().One().Should().Be.False();
            strings.Is().Not.Contains().Exactly(1).Should().Be.False();
            strings.Is().Not.Contains().Exactly(2).Should().Be.True();
            strings.Is().Not.Contains().AtLeast(1).Should().Be.False();
            strings.Is().Not.Contains().AtLeast(0).Should().Be.False();
            strings.Is().Not.Contains().AtLeast(2).Should().Be.True();
            strings.Is().Not.Contains().NoMoreThan(1).Should().Be.False();
            strings.Is().Not.Contains().NoMoreThan(2).Should().Be.False();
            strings.Is().Not.Contains().NoMoreThan(0).Should().Be.True();
        }

    }
}

